www.gusucode.com > VC 2D游戏编辑器-源码程序 > VC 2D游戏编辑器-源码程序/code/mapedit_source/gridlist.cpp
//Download by http://www.NewXing.com // gridlist.cpp : implementation file // #include "stdafx.h" #include "MapEdit.h" #include "gridlist.h" #include "MainFrm.h" #include "MapEditView.h" #include "script\\script.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #include "goods\\goods.h" #include "magic\\magic.h" extern bool bIsDirty; extern CView * pView; extern WORD wEditStatus; extern int nSelectedScript; ///////////////////////////////////////////////////////////////////////////// // Cgridlist Cgridlist::Cgridlist() { m_CurSubItem = -1; m_pListEdit = 0; } Cgridlist::~Cgridlist() { delete m_pListEdit; } BEGIN_MESSAGE_MAP(Cgridlist, CListCtrl) //{{AFX_MSG_MAP(Cgridlist) ON_WM_LBUTTONDOWN() ON_WM_HSCROLL() ON_WM_VSCROLL() ON_NOTIFY_REFLECT(LVN_BEGINLABELEDIT, OnBeginlabeledit) ON_NOTIFY_REFLECT(LVN_ENDLABELEDIT, OnEndlabeledit) ON_WM_RBUTTONDOWN() ON_COMMAND(IDC_GOODS_INSERT, OnGoodsInsert) ON_COMMAND(IDC_GOODS_DEL, OnGoodsDel) ON_COMMAND(IDC_MAGIC_DEL, OnMagicDel) ON_COMMAND(IDC_MAGIC_INSERT, OnMagicInsert) ON_COMMAND(IDC_SCRIPT_DEL, OnScriptDel) ON_COMMAND(IDC_SCRIPT_INSERT, OnScriptInsert) ON_WM_MOUSEMOVE() ON_COMMAND(IDC_PARAMETER_DEL, OnParameterDel) ON_COMMAND(IDC_PARAMETER_INSERT, OnParameterInsert) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // Cgridlist message handlers BOOL Cgridlist::PrepareControl(WORD wStyle) { m_wStyle = wStyle; ASSERT( m_hWnd ); DWORD dwStyle = GetWindowLong(m_hWnd, GWL_STYLE); dwStyle &= ~(LVS_TYPEMASK); dwStyle &= ~(LVS_EDITLABELS); // Make sure we have report view and send edit label messages. SetWindowLong( m_hWnd, GWL_STYLE, dwStyle | LVS_REPORT ); // Enable the full row selection and the drag drop of headers. DWORD styles = LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP ; // Use macro since this is new and not in MFC. ListView_SetExtendedListViewStyleEx(m_hWnd, styles, styles ); return TRUE; } void Cgridlist::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default LVHITTESTINFO ht; ht.pt = point; // Test for which subitem was clicked. // Use macro since this is new and not in MFC. int rval = ListView_SubItemHitTest( m_hWnd, &ht ); // Store the old column number and set the new column value. int oldsubitem = m_CurSubItem; m_CurSubItem = IndexToOrder( ht.iSubItem ); CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0); // Make the column fully visible. // We have to take into account that the columns may be reordered MakeColumnVisible( Header_OrderToIndex( pHeader->m_hWnd, m_CurSubItem ) ); // Store old state of the item. int state = GetItemState( ht.iItem, LVIS_FOCUSED ); // Call default left button click is here just before we might bail. // Also updates the state of the item. CListCtrl::OnLButtonDown(nFlags, point); // Bail if the state from before was not focused or the // user has not already clicked on this cell. if( !state || m_CurSubItem == -1 || oldsubitem != m_CurSubItem ) return; int doedit = 0; // If we are in column 0 make sure that the user clicked on // the item label. if( 0 == ht.iSubItem ) { if((wEditStatus != 4)&&(wEditStatus != 5)) if( ht.flags & LVHT_ONITEMLABEL ) doedit = 1; } else if((wEditStatus !=4)||(ht.iItem % ((Max_Script_Key>>2)+1) != 0)) { doedit = 1; } if( !doedit ) return; // Send Notification to parent of ListView ctrl CString str; str = GetItemText( ht.iItem, ht.iSubItem ); LV_DISPINFO dispinfo; dispinfo.hdr.hwndFrom = m_hWnd; dispinfo.hdr.idFrom = GetDlgCtrlID(); dispinfo.hdr.code = LVN_BEGINLABELEDIT; dispinfo.item.mask = LVIF_TEXT; //行 dispinfo.item.iItem = ht.iItem; //列 dispinfo.item.iSubItem = ht.iSubItem; dispinfo.item.pszText = (LPTSTR)((LPCTSTR)str); dispinfo.item.cchTextMax = str.GetLength(); if (bIsDirty==false) // changed { bIsDirty=true; ((CMapEditView*)pView)->SetWinTitle(); } GetParent()->SendMessage( WM_NOTIFY, GetDlgCtrlID(), (LPARAM)&dispinfo ); } BOOL Cgridlist::PositionControl( CWnd * pWnd, int iItem, int iSubItem ) { ASSERT( pWnd && pWnd->m_hWnd ); ASSERT( iItem >= 0 ); // Make sure that the item is visible if( !EnsureVisible( iItem, TRUE ) ) return NULL; // Make sure that nCol is valid CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0); int nColumnCount = pHeader->GetItemCount(); ASSERT( iSubItem >= 0 && iSubItem < nColumnCount ); if( iSubItem >= nColumnCount || // We have to take into account that the header may be reordered GetColumnWidth(Header_OrderToIndex( pHeader->m_hWnd,iSubItem)) < 5 ) { return 0; } // Get the header order array to sum the column widths up to the selected cell. int *orderarray = new int[ nColumnCount ]; Header_GetOrderArray( pHeader->m_hWnd, nColumnCount, orderarray ); int offset = 0; int i; for( i = 0; orderarray[i] != iSubItem; i++ ) offset += GetColumnWidth( orderarray[i] ); int colwidth = GetColumnWidth( iSubItem ); delete[] orderarray; CRect rect; GetItemRect( iItem, &rect, LVIR_BOUNDS ); // Scroll if we need to expose the column CRect rcClient; GetClientRect( &rcClient ); if( offset + rect.left < 0 || offset + colwidth + rect.left > rcClient.right ) { CSize size; size.cx = offset + rect.left; size.cy = 0; Scroll( size ); rect.left -= size.cx; } rect.left += offset+4; rect.right = rect.left + colwidth - 3 ; // The right end of the control should not go past the edge // of the grid control. if( rect.right > rcClient.right) rect.right = rcClient.right; pWnd->MoveWindow( &rect ); return 1; } void Cgridlist::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult) { // This function is called by the control in different // stages during the control drawing process. NMLVCUSTOMDRAW *pCD = (NMLVCUSTOMDRAW*)pNMHDR; // By default set the return value to do the default behavior. *pResult = 0; switch( pCD->nmcd.dwDrawStage ) { case CDDS_PREPAINT: // First stage (for the whole control) // Tell the control we want to receive drawing messages // for drawing items. *pResult = CDRF_NOTIFYITEMDRAW; // The next stage is handled in the default: break; case CDDS_ITEMPREPAINT | CDDS_SUBITEM: // Stage three (called for each subitem of the focused item) { // We don't want to draw anything here, but we need to respond // of DODEFAULT will be the next stage. // Tell the control we want to handle drawing after the subitem // is drawn. *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NOTIFYPOSTPAINT; } break; case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM: // Stage four (called for each subitem of the focused item) { // We do the drawing here (well maybe). // This is actually after the control has done its drawing // on the subitem. Since drawing a cell is near instantaneous // the user won't notice. int subitem = pCD->iSubItem; // Only do our own drawing if this subitem has focus at the item level. if( (pCD->nmcd.uItemState & CDIS_FOCUS) ) { // If this subitem is the subitem with the current focus, // draw it. Otherwise let the control draw it. CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0); // We have to take into account the possibility that the // columns may be reordered. if( subitem == Header_OrderToIndex( pHeader->m_hWnd, m_CurSubItem ) ) { // POSTERASE CDC* pDC = CDC::FromHandle(pCD->nmcd.hdc); // Calculate the offset of the text from the right and left of the cell. int offset = pDC->GetTextExtent(_T(" "), 1 ).cx*2; // The rect for the cell gives correct left and right values. CRect rect = pCD->nmcd.rc; CRect bounds; GetItemRect( pCD->nmcd.dwItemSpec, &bounds, LVIR_BOUNDS ); // Get the top and bottom from the item itself. rect.top = bounds.top; rect.bottom = bounds.bottom; // Adjust rectangle for horizontal scroll and first column label { if( subitem == 0 ) { CRect lrect; GetItemRect( pCD->nmcd.dwItemSpec, &lrect, LVIR_LABEL ); rect.left = lrect.left; rect.right = lrect.right; } else { rect.right += bounds.left; rect.left += bounds.left; } } // Clear the background with button face color pDC->FillRect(rect, &CBrush(::GetSysColor(COLOR_3DFACE))); // PREPAINT CString str; str = GetItemText( pCD->nmcd.dwItemSpec, pCD->iSubItem ); // Deflate the rect by the horizontal offset. rect.DeflateRect( offset, 0 ); // You could also make this column alignment sensitive here. pDC->DrawText( str, rect, DT_SINGLELINE|DT_NOPREFIX|DT_LEFT|DT_VCENTER|DT_END_ELLIPSIS); // POSTPAINT // Draw rounded edge rect.InflateRect( offset, 0 ); pDC->Draw3dRect( &rect, ::GetSysColor(COLOR_3DSHADOW), ::GetSysColor(COLOR_3DFACE) ); rect.DeflateRect( 1, 1 ); pDC->Draw3dRect( &rect, ::GetSysColor(COLOR_3DDKSHADOW), ::GetSysColor(COLOR_3DHILIGHT) ); // Tell the control that we handled the drawing for this subitem. *pResult = CDRF_SKIPDEFAULT; } } } break; default: // Stage two handled here. (called for each item) if( !(pCD->nmcd.uItemState & CDIS_FOCUS) ) { // If this item does not have focus, let the // control draw the whole item. *pResult = CDRF_DODEFAULT; } else { // If this item has focus, tell the control we want // to handle subitem drawing. *pResult = CDRF_NOTIFYSUBITEMDRAW; } break; } } void Cgridlist::MakeColumnVisible(int nCol) { if( nCol < 0 ) return; // Get the order array to total the column offset. CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0); int colcount = pHeader->GetItemCount(); ASSERT( nCol < colcount ); int *orderarray = new int[ colcount ]; Header_GetOrderArray( pHeader->m_hWnd, colcount, orderarray ); // Get the column offset int offset = 0; for( int i = 0; orderarray[i] != nCol; i++ ) offset += GetColumnWidth( orderarray[i] ); int colwidth = GetColumnWidth( nCol ); delete[] orderarray; CRect rect; GetItemRect( 0, &rect, LVIR_BOUNDS ); // Now scroll if we need to expose the column CRect rcClient; GetClientRect( &rcClient ); if( offset + rect.left < 0 || offset + colwidth + rect.left > rcClient.right ) { CSize size; size.cx = offset + rect.left; size.cy = 0; Scroll( size ); rect.left -= size.cx; } } int Cgridlist::IndexToOrder( int iIndex ) { // Since the control only provide the OrderToIndex macro, // we have to provide the IndexToOrder. This translates // a column index value to a column order value. CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0); int colcount = pHeader->GetItemCount(); int *orderarray = new int[ colcount ]; Header_GetOrderArray( pHeader->m_hWnd, colcount, orderarray ); int i; for( i=0; i<colcount; i++ ) { if( orderarray[i] == iIndex ) return i; } return -1; } BOOL Cgridlist::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if(pMsg->message == WM_KEYDOWN) { // Handle the keystrokes for the left and right keys // to move the cell selection left and right. // Handle F2 to commence edit mode from the keyboard. // Only handle these if the grid control has the focus. // (Messages also come through here for the edit control // and we don't want them. if( this == GetFocus() ) { switch( pMsg->wParam ) { case VK_LEFT: { // Decrement the order number. m_CurSubItem--; if( m_CurSubItem < -1 ) { // This indicates that the whole row is selected and F2 means nothing. m_CurSubItem = -1; } else { CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0); // Make the column visible. // We have to take into account that the header // may be reordered. MakeColumnVisible( Header_OrderToIndex( pHeader->m_hWnd, m_CurSubItem ) ); // Invalidate the item. int iItem = GetNextItem( -1, LVNI_FOCUSED ); if( iItem != -1 ) { CRect rcBounds; GetItemRect(iItem, rcBounds, LVIR_BOUNDS); InvalidateRect( &rcBounds ); } } } return TRUE; case VK_RIGHT: { // Increment the order number. m_CurSubItem++; CHeaderCtrl* pHeader = (CHeaderCtrl*) GetDlgItem(0); int nColumnCount = pHeader->GetItemCount(); // Don't go beyond the last column. if( m_CurSubItem > nColumnCount -1 ) { m_CurSubItem = nColumnCount-1; } else { // We have to take into account that the header // may be reordered. MakeColumnVisible( Header_OrderToIndex( pHeader->m_hWnd, m_CurSubItem ) ); int iItem = GetNextItem( -1, LVNI_FOCUSED ); // Invalidate the item. if( iItem != -1 ) { CRect rcBounds; GetItemRect(iItem, rcBounds, LVIR_BOUNDS); InvalidateRect( &rcBounds ); } } } return TRUE; case VK_F2: // Enter nondestructive edit mode. { int iItem = GetNextItem( -1, LVNI_FOCUSED ); if( m_CurSubItem != -1 && iItem != -1 ) { // Send Notification to parent of ListView ctrl CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0); CString str; // We have to take into account that the header // may be reordered. str = GetItemText( iItem, Header_OrderToIndex( pHeader->m_hWnd, m_CurSubItem ) ); LV_DISPINFO dispinfo; dispinfo.hdr.hwndFrom = m_hWnd; dispinfo.hdr.idFrom = GetDlgCtrlID(); dispinfo.hdr.code = LVN_BEGINLABELEDIT; dispinfo.item.mask = LVIF_TEXT; dispinfo.item.iItem = iItem; // We have to take into account that the header // may be reordered. dispinfo.item.iSubItem = Header_OrderToIndex( pHeader->m_hWnd, m_CurSubItem ); dispinfo.item.pszText = (LPTSTR)((LPCTSTR)str); dispinfo.item.cchTextMax = str.GetLength(); // Send message to the parent that we are ready to edit. GetParent()->SendMessage( WM_NOTIFY, GetDlgCtrlID(), (LPARAM)&dispinfo ); } } break; default: break; } } } return CListCtrl::PreTranslateMessage(pMsg); } void Cgridlist::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { // TODO: Add your message handler code here and/or call default if( GetFocus() != this ) SetFocus(); CListCtrl::OnHScroll(nSBCode, nPos, pScrollBar); } void Cgridlist::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { // TODO: Add your message handler code here and/or call default if( GetFocus() != this ) SetFocus(); CListCtrl::OnVScroll(nSBCode, nPos, pScrollBar); } void Cgridlist::OnBeginlabeledit(NMHDR* pNMHDR, LRESULT* pResult) { LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR; // TODO: Add your control notification handler code here CString str = pDispInfo->item.pszText; int item = pDispInfo->item.iItem; int subitem = pDispInfo->item.iSubItem; // Construct and create the custom multiline edit control. // We could just as well have used a combobox, checkbox, // rich text control, etc. m_pListEdit = new Cinplaceedit( item, subitem, str ); // Start with a small rectangle. We'll change it later. CRect rect( 0,0,1,1 ); DWORD dwStyle = ES_LEFT; dwStyle |= WS_BORDER|WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_AUTOVSCROLL; m_pListEdit->Create( dwStyle, rect, this, 103 ); // Have the Grid position and size the custom edit control this->PositionControl( m_pListEdit, item, subitem ); // Have the edit box size itself to its content. m_pListEdit->CalculateSize(); // Return TRUE so that the list control will hnadle NOT edit label itself. *pResult = 1; } void Cgridlist::OnEndlabeledit(NMHDR* pNMHDR, LRESULT* pResult) { LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR; // TODO: Add your control notification handler code here int item = pDispInfo->item.iItem; int subitem = pDispInfo->item.iSubItem; // This is coming from the grid list control notification. if( m_pListEdit ) { CString str; int iText; if( pDispInfo->item.pszText ) { switch(subitem) { case 0: switch(wEditStatus) { case 1: iText = atoi(pDispInfo->item.pszText); if(( iText < MaxGoods+1)&&(iText > 0)) { LV_ITEM lvitem; lvitem.mask = LVIF_TEXT | LVIF_IMAGE; lvitem.iItem = item; lvitem.iSubItem = 0; lvitem.iImage = iText-1; lvitem.pszText = pDispInfo->item.pszText; this->SetItem(&lvitem); } break; case 2: iText = atoi(pDispInfo->item.pszText); if(( iText < MaxMagic+1)&&(iText > 0)) { LV_ITEM lvitem; lvitem.mask = LVIF_TEXT | LVIF_IMAGE; lvitem.iItem = item; lvitem.iSubItem = 0; lvitem.iImage = iText-1; lvitem.pszText = pDispInfo->item.pszText; this->SetItem(&lvitem); } break; case 3: case 4: this->SetItemText( item, subitem, pDispInfo->item.pszText ); break; } break; case 1: switch(wEditStatus) { case 1: case 2: iText = atoi(pDispInfo->item.pszText); if(( iText <= 10)&&(iText >= 0)) { this->SetItemText( item, subitem, pDispInfo->item.pszText ); } break; case 3: case 4: case 5: this->SetItemText( item, subitem, pDispInfo->item.pszText ); break; } break; case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: switch(wEditStatus) { case 1: case 2: iText = atoi(pDispInfo->item.pszText); this->SetItemText( item, subitem, pDispInfo->item.pszText ); break; case 3: case 4: this->SetItemText( item, subitem, pDispInfo->item.pszText ); break; } break; case 15: switch(wEditStatus) { case 1: this->SetItemText( item, subitem, pDispInfo->item.pszText ); break; case 2: iText = atoi(pDispInfo->item.pszText); if(( iText <= 100)&&(iText >= 0)) { this->SetItemText( item, subitem, pDispInfo->item.pszText ); } break; case 4: this->SetItemText( item, subitem, pDispInfo->item.pszText ); break; } break; case 16: case 17: switch(wEditStatus) { case 2: iText = atoi(pDispInfo->item.pszText); if(( iText <= 100)&&(iText >= 0)) { this->SetItemText( item, subitem, pDispInfo->item.pszText ); } break; case 4: this->SetItemText( item, subitem, pDispInfo->item.pszText ); break; } break; case 18: switch(wEditStatus) { case 2: this->SetItemText( item, subitem, pDispInfo->item.pszText ); break; case 4: this->SetItemText( item, subitem, pDispInfo->item.pszText ); break; } default: this->SetItemText( item, subitem, pDispInfo->item.pszText ); break; } } delete m_pListEdit; m_pListEdit = 0; } *pResult = 0; } void Cgridlist::OnRButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CMenu popmenu, *popup; switch(wEditStatus) { case 1: if(!popmenu.LoadMenu(IDR_GOODS_POPMENU)) //装入菜单资源。 { MessageBox("物品菜单装入失败!","错误",MB_OK|MB_ICONERROR); return; } break; case 2: if(!popmenu.LoadMenu(IDR_MAGIC_POPMENU)) //装入菜单资源。 { MessageBox("魔法菜单装入失败!","错误",MB_OK|MB_ICONERROR); return; } break; case 3: if(!popmenu.LoadMenu(IDR_SCRIPT_POPMENU)) //装入菜单资源。 { MessageBox("脚本菜单装入失败!","错误",MB_OK|MB_ICONERROR); return; } break; case 5: if(!popmenu.LoadMenu(IDR_PARAMETER_POPMENU)) //装入菜单资源。 { MessageBox("脚本菜单装入失败!","错误",MB_OK|MB_ICONERROR); return; } break; } if(wEditStatus != 4) { popup = popmenu.GetSubMenu(0); popup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,point.x, point.y+60, this ); LVHITTESTINFO ht; ht.pt = point; ListView_SubItemHitTest( m_hWnd, &ht ); int oldsubitem = m_CurSubItem; m_CurSubItem = ht.iItem ; if (bIsDirty==false) // changed { bIsDirty=true; // ((CMapEditView*)((CMainFrame*)AfxGetMainWnd())->GetActiveView())->SetWinTitle(); ((CMapEditView*)pView)->SetWinTitle(); } } CListCtrl::OnRButtonDown(nFlags, point); } void Cgridlist::OnGoodsInsert() { // TODO: Add your command handler code here LV_ITEM lvitem; int i, j; char iID[100]; lvitem.mask = LVIF_TEXT | LVIF_IMAGE; if(m_CurSubItem == -1) m_CurSubItem = this->GetItemCount(); lvitem.mask = LVIF_TEXT | LVIF_IMAGE; lvitem.iItem = this->GetItemCount(); lvitem.iSubItem = 0; lvitem.iImage = 0; lvitem.pszText = ""; this->InsertItem(&lvitem); for(j = this->GetItemCount()-1; j > m_CurSubItem; j--) { lvitem.mask = LVIF_TEXT | LVIF_IMAGE; lvitem.iItem = j; lvitem.iSubItem = 0; strcpy(iID, this->GetItemText(j-1, 0)); i = atoi(iID); lvitem.iImage = i-1; lvitem.pszText = iID; this->SetItem(&lvitem); for(i = 1; i < MaxGoodsStatus; i++) { lvitem.mask = LVIF_TEXT; lvitem.iItem = j; lvitem.iSubItem = i; lvitem.iImage = 0; strcpy(iID, this->GetItemText(j-1, i)); lvitem.pszText = iID; this->SetItem(&lvitem); } } lvitem.mask = LVIF_TEXT | LVIF_IMAGE; lvitem.iItem = m_CurSubItem; lvitem.iSubItem = 0; lvitem.iImage = 0; lvitem.pszText = "1"; this->SetItem(&lvitem); for(i = 1; i < MaxGoodsStatus; i++) { lvitem.mask = LVIF_TEXT; lvitem.iItem = m_CurSubItem; lvitem.iSubItem = i; lvitem.iImage = 0; lvitem.pszText = "0"; this->SetItem(&lvitem); } } void Cgridlist::OnGoodsDel() { // TODO: Add your command handler code here if(m_CurSubItem != -1) this->DeleteItem(m_CurSubItem); } void Cgridlist::OnMagicDel() { // TODO: Add your command handler code here if(m_CurSubItem != -1) this->DeleteItem(m_CurSubItem); } void Cgridlist::OnMagicInsert() { // TODO: Add your command handler code here LV_ITEM lvitem; int i, j; char iID[100]; if(m_CurSubItem == -1) m_CurSubItem = this->GetItemCount(); lvitem.mask = LVIF_TEXT | LVIF_IMAGE; lvitem.iItem = this->GetItemCount(); lvitem.iSubItem = 0; lvitem.iImage = 0; lvitem.pszText = ""; this->InsertItem(&lvitem); for(j = this->GetItemCount()-1; j > m_CurSubItem; j--) { lvitem.mask = LVIF_TEXT | LVIF_IMAGE; lvitem.iItem = j; lvitem.iSubItem = 0; strcpy(iID, this->GetItemText(j-1, 0)); i = atoi(iID); lvitem.iImage = i-1; lvitem.pszText = iID; this->SetItem(&lvitem); for(i = 1; i < MaxMagicStatus; i++) { lvitem.mask = LVIF_TEXT; lvitem.iItem = j; lvitem.iSubItem = i; lvitem.iImage = 0; strcpy(iID, this->GetItemText(j-1, i)); lvitem.pszText = iID; this->SetItem(&lvitem); } } lvitem.mask = LVIF_TEXT | LVIF_IMAGE; lvitem.iItem = m_CurSubItem; lvitem.iSubItem = 0; lvitem.iImage = 0; lvitem.pszText = "1"; this->SetItem(&lvitem); for(i = 1; i < MaxMagicStatus; i++) { lvitem.mask = LVIF_TEXT; lvitem.iItem = m_CurSubItem; lvitem.iSubItem = i; lvitem.iImage = 0; lvitem.pszText = "0"; this->SetItem(&lvitem); } } void Cgridlist::OnScriptDel() { // TODO: Add your command handler code here if(m_CurSubItem != -1) this->DeleteItem(m_CurSubItem); int i; char iID[50]; LV_ITEM lvitem; for(i = m_CurSubItem; i < this->GetItemCount(); i++) { lvitem.mask = LVIF_TEXT; lvitem.iItem = i; lvitem.iSubItem = 0; lvitem.iImage = 0; sprintf(iID, "%d", i); lvitem.pszText = iID; this->SetItem(&lvitem); } } void Cgridlist::OnScriptInsert() { // TODO: Add your command handler code here LV_ITEM lvitem; char iID[100]; int i, j; lvitem.mask = LVIF_TEXT | LVIF_IMAGE; if(m_CurSubItem == -1) m_CurSubItem = this->GetItemCount(); lvitem.iItem = this->GetItemCount(); lvitem.iSubItem = 0; lvitem.iImage = 0; lvitem.pszText = ""; this->InsertItem(&lvitem); for(j = this->GetItemCount()-1; j > m_CurSubItem; j--) { lvitem.mask = LVIF_TEXT; lvitem.iItem = j; lvitem.iSubItem = 0; lvitem.iImage = 0; sprintf(iID, "%d", j); lvitem.pszText = iID; this->SetItem(&lvitem); for(i = 1; i < 8; i++) { lvitem.mask = LVIF_TEXT; lvitem.iItem = j; lvitem.iSubItem = i; lvitem.iImage = 0; strcpy(iID, this->GetItemText(j-1, i)); lvitem.pszText = iID; this->SetItem(&lvitem); } } lvitem.mask = LVIF_TEXT; lvitem.iItem = m_CurSubItem; lvitem.iSubItem = 0; lvitem.iImage = 0; sprintf(iID, "%d", m_CurSubItem); lvitem.pszText = iID; this->SetItem(&lvitem); lvitem.mask = LVIF_TEXT; lvitem.iItem = m_CurSubItem; lvitem.iSubItem = 1; lvitem.iImage = 0; lvitem.pszText = cScriptText[nSelectedScript]; this->SetItem(&lvitem); for(i = 2; i < 8; i++) { lvitem.mask = LVIF_TEXT; lvitem.iItem = m_CurSubItem; lvitem.iSubItem = i; lvitem.iImage = 0; lvitem.pszText = ""; this->SetItem(&lvitem); } } void Cgridlist::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default switch(wEditStatus) { case 3: LVHITTESTINFO ht; static int nCurrentLine = 0; int i; ht.pt = point; int rval = ListView_SubItemHitTest( m_hWnd, &ht ); char str[30]; memcpy(str, GetItemText( ht.iItem, 1 ), 30); if(str[0] != '\0') { for(i = 0; i < Max_Script_Key; i++) { if(!strcmp(cScriptText[i], str)) break; } if(i != Max_Script_Key) { nCurrentLine = i; } } ((CMainFrame *)AfxGetMainWnd())->m_wndStatusBar.SetPaneText(0, cScriptHelp[nCurrentLine]); break; } CListCtrl::OnMouseMove(nFlags, point); } void Cgridlist::OnParameterDel() { // TODO: Add your command handler code here if(m_CurSubItem != -1) this->DeleteItem(m_CurSubItem); int i; char iID[50]; LV_ITEM lvitem; for(i = m_CurSubItem; i < this->GetItemCount(); i++) { lvitem.mask = LVIF_TEXT; lvitem.iItem = i; lvitem.iSubItem = 0; lvitem.iImage = 0; sprintf(iID, "%d", i); lvitem.pszText = iID; this->SetItem(&lvitem); } } void Cgridlist::OnParameterInsert() { // TODO: Add your command handler code here LV_ITEM lvitem; char iID[100]; int j; lvitem.mask = LVIF_TEXT | LVIF_IMAGE; if(m_CurSubItem == -1) m_CurSubItem = this->GetItemCount(); lvitem.iItem = this->GetItemCount(); lvitem.iSubItem = 0; lvitem.iImage = 0; lvitem.pszText = ""; this->InsertItem(&lvitem); for(j = this->GetItemCount()-1; j > m_CurSubItem; j--) { lvitem.mask = LVIF_TEXT; lvitem.iItem = j; lvitem.iSubItem = 0; lvitem.iImage = 0; sprintf(iID, "%d", j); lvitem.pszText = iID; this->SetItem(&lvitem); lvitem.mask = LVIF_TEXT; lvitem.iItem = j; lvitem.iSubItem = 1; lvitem.iImage = 0; strcpy(iID, this->GetItemText(j-1, 1)); lvitem.pszText = iID; this->SetItem(&lvitem); } lvitem.mask = LVIF_TEXT; lvitem.iItem = m_CurSubItem; lvitem.iSubItem = 0; lvitem.iImage = 0; sprintf(iID, "%d", m_CurSubItem); lvitem.pszText = iID; this->SetItem(&lvitem); lvitem.mask = LVIF_TEXT; lvitem.iItem = m_CurSubItem; lvitem.iSubItem = 1; lvitem.iImage = 0; sprintf(iID, "a%d", m_CurSubItem); lvitem.pszText = iID; this->SetItem(&lvitem); }